var queryPaybackPage;
var queryPaybackedPage;

$(document).ready(function() {
	
	Date.prototype.pattern=function(fmt) {        
    var o = {        
    "M+" : this.getMonth()+1, //月份        
    "d+" : this.getDate(), //日        
    "h+" : this.getHours()%12 == 0 ? 12 : this.getHours()%12, //小时        
    "H+" : this.getHours(), //小时        
    "m+" : this.getMinutes(), //分        
    "s+" : this.getSeconds(), //秒        
    "q+" : Math.floor((this.getMonth()+3)/3), //季度        
    "S" : this.getMilliseconds() //毫秒        
    };        
    var week = {        
    "0" : "\u65e5",        
    "1" : "\u4e00",        
    "2" : "\u4e8c",        
    "3" : "\u4e09",        
    "4" : "\u56db",        
    "5" : "\u4e94",        
    "6" : "\u516d"     
    };        
    if(/(y+)/.test(fmt)){        
            fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));        
    }        
    if(/(E+)/.test(fmt)){        
            fmt=fmt.replace(RegExp.$1, ((RegExp.$1.length>1) ? (RegExp.$1.length>2 ? "\u661f\u671f" : "\u5468") : "")+week[this.getDay()+""]);        
    }        
    for(var k in o){        
            if(new RegExp("("+ k +")").test(fmt)){        
                    fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));        
            }        
    }        
    return fmt;        
}
	//	init tab1
	queryPayback();
	$('#queryPaybackForm').submit(function() {
		$("#paybackPageNo").val("1");
		queryPayback();
		return false;
	});
	
	$("#queryNextPageButton").click(queryPayback_nextPage);
	$("#queryPrevPageButton").click(queryPayback_prePage);
	$("#queryFirstPageButton").click(queryPayback_firstPage);
	$("#queryLastPageButton").click(queryPayback_lastPage);
//	init tab2
	queryPaybacked();
	$('#queryPaybackedForm').submit(function() {
		$("#paybackedPageNo").val("1");
		queryPaybacked();
		return false;
	});
	
	$("#queryPaybackedNextPageButton").click(queryPaybacked_nextPage);
	$("#queryPaybackedPrevPageButton").click(queryPaybacked_prePage);
	$("#queryPaybackedFirstPageButton").click(queryPaybacked_firstPage);
	$("#queryPaybackedLastPageButton").click(queryPaybacked_lastPage);
});

function queryPayback() {
	$("#paybacktable tr:not(:first)").empty();
	var paybackOptions = {
		success : showPaybackResponse
	};
	$('#queryPaybackForm').ajaxSubmit(paybackOptions);
}

function queryPayback_nextPage(){
	$("#paybackPageNo").val(queryPaybackPage.nextPage);
	queryPayback();
}
function queryPayback_prePage(){
	$("#paybackPageNo").val(queryPaybackPage.prePage);
	queryPayback();
}
function queryPayback_firstPage(){
	$("#paybackPageNo").val("1");
	queryPayback();
}
function queryPayback_lastPage(){
	$("#paybackPageNo").val(queryPaybackPage.totalPages);
	queryPayback();
}

function showPaybackResponse(responseText, statusText, xhr, $form) {
	queryPaybackPage=responseText;
	$("#paybackPageNo").val(queryPaybackPage.pageNo);
	$("#paybackTotalPage").text(queryPaybackPage.totalPages);
	for(var i = 0; i < queryPaybackPage.result.length; i++) {
		var data = queryPaybackPage.result[i];
		if(i % 2 == 0) {
			$("#paybacktable").append("<tr class='ggkj_tdColr'><td>" + data.investId + "</td><td>" + data.customerNo + "</td><td>" + data.customerName + "</td><td>" + data.cardNo + "</td><td>" + data.lendingNo + "</td><td>" + data.productType + "</td><td>" + data.paybackAmt + "</td><td><a href='#'>test</a></td></tr>");
		} else {
			$("#paybacktable").append("<tr><td>" + data.investId + "</td><td>" + data.customerNo + "</td><td>" + data.customerName + "</td><td>" + data.cardNo + "</td><td>" + data.lendingNo + "</td><td>" + data.productType + "</td><td>" + data.paybackAmt + "</td><td><a href='#'>test</a></td></tr>");
		}
	}
}

function queryPaybacked() {
	$("#paybackedtable tr:not(:first)").empty();
	var paybackedOptions = {
		success : showPaybackedResponse
	};
	$('#queryPaybackedForm').ajaxSubmit(paybackedOptions);
}

function queryPaybacked_nextPage(){
	$("#paybackedPageNo").val(queryPaybackedPage.nextPage);
	queryPaybacked();
}
function queryPaybacked_prePage(){
	$("#paybackedPageNo").val(queryPaybackedPage.prePage);
	queryPaybacked();
}
function queryPaybacked_firstPage(){
	$("#paybackedPageNo").val("1");
	queryPaybacked();
}
function queryPaybacked_lastPage(){
	$("#paybackedPageNo").val(queryPaybackedPage.totalPages);
	queryPaybacked();
}

function showPaybackedResponse(responseText, statusText, xhr, $form) {
	queryPaybackedPage=responseText;
	$("#paybackedPageNo").val(queryPaybackedPage.pageNo);
	$("#paybackedTotalPage").text(queryPaybackedPage.totalPages);
	for(var i = 0; i < queryPaybackedPage.result.length; i++) {
		var data = queryPaybackedPage.result[i];
		var payDate=new Date(data.payDate).pattern("yyyy-MM-dd");
		if(i % 2 == 0) {
			$("#paybackedtable").append("<tr class='ggkj_tdColr'><td>" + data.investInfo.id + "</td><td>" + data.investInfo.customerInfo.customerCode + "</td><td>" + data.investInfo.customerInfo.cnName + "</td><td>" + data.investInfo.customerInfo.cardId + "</td><td>" + data.investInfo.lendingNo + "</td><td>" + data.investInfo.productTypeDisplay + "</td><td>" + data.amt + "</td><td>" + data.recBankInfo.accNo + "</td><td>"+payDate+"</td></tr>");
		} else {
			$("#paybackedtable").append("<tr><td>" + data.investInfo.id + "</td><td>" + data.investInfo.customerInfo.customerCode + "</td><td>" + data.investInfo.customerInfo.cnName + "</td><td>" + data.investInfo.customerInfo.cardId + "</td><td>" + data.investInfo.lendingNo + "</td><td>" + data.investInfo.productTypeDisplay + "</td><td>" + data.amt + "</td><td>" + data.recBankInfo.accNo + "</td><td>"+payDate+"</td></tr>");
		}
	}
}